package com.example.springboot.controller;

import com.example.springboot.entity.LiveClass;
import com.example.springboot.entity.Message;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class LiveClassController {
    private List<LiveClass> liveClasses = new ArrayList<>();

    @PostMapping("/createLiveClass")
    @CrossOrigin
    public String createLiveClass(@RequestBody LiveClass liveClass) {
        liveClasses.add(liveClass);
        return "直播课堂创建成功";
    }

    @PostMapping("/removeLiveClass")
    @CrossOrigin
    public String removeLiveClass(@RequestParam String roomId) {
        for (LiveClass liveClass : liveClasses) {
            if (liveClass.getRoomId().equals(roomId)){
                liveClasses.remove(liveClass);
                break;
            }
        }
        return "直播课堂删除成功";
    }

    @GetMapping("/getLiveClasses")
    @CrossOrigin
    public List<LiveClass> getLiveClasses() {
        return liveClasses;
    }
}
